<template>
    <div class="box">
        <el-row>
            <el-col :span="22" :push="1">
                <div class="grid-content bg-purple" style="height: 77px">
                    <span style="line-height: 77px; font-size: 14px"> </span>
                    <span style="margin-left: 20px">
                        <el-button type="primary" size="small" @click="openCheer">添加案库</el-button>
                    </span>
                </div>
            </el-col>
        </el-row>
        <!-- 搜索栏start -->
        <el-row>
            <el-col :span="22" :push="1">
                <div class="grid-content bg-purple">
                    <div style="width: 100%; margin-left: 20px;">
                        <span style="margin-left: 20px;">
                            <el-form :inline="true" :model="formInline" size="mini" class="demo-form-inline">
                                <el-form-item label="案库名称">
                                    <el-input v-model="formInline.caselockerName"></el-input>
                                </el-form-item>
                                <el-form-item label="归属公司">
                                    <el-select v-model="formInline.recordCompany">
                                        <el-option v-for="item in carNumbers" :key="item.id" :label="item.recordCompany"
                                            :value="item.id">
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="创建时间">
                                    <el-date-picker v-model="timeArr" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                                        type="daterange" range-separator="至" start-placeholder="开始日期"
                                        end-placeholder="结束日期">
                                    </el-date-picker>
                                </el-form-item>
                                <el-form-item label="更新时间">
                                    <el-date-picker v-model="timeArr1" format="yyyy-MM-dd" value-format="yyyy-MM-dd"
                                        type="daterange" range-separator="至" start-placeholder="开始日期"
                                        end-placeholder="结束日期">
                                    </el-date-picker>
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" @click="onSubmit">搜索</el-button>
                                    <el-button type="primary" @click="reset">重置</el-button>
                                </el-form-item>
                            </el-form>
                        </span>
                    </div>
                </div>
            </el-col>
        </el-row>
        <!-- 搜索栏end -->
        <!-- 表格 -->
        <el-row>
            <el-col :span="22" :push="1">
                <div class="grid-content bg-purple">
                    <span style="padding-left: 10px">
                        <el-table :data="tableData" border="" style="width:100%;">
                            <el-table-column fixed prop="id" label="流水号" width="100">
                            </el-table-column>
                            <el-table-column prop="caselockerId" label="案库号" width="160">
                            </el-table-column>
                            <el-table-column prop="caselockerName" label="案库名称" width="140">
                            </el-table-column>
                            <el-table-column prop="recordName" label="归属全宗" width="140">
                            </el-table-column>
                            <el-table-column prop="rid" label="全宗号" width="100">
                            </el-table-column>
                            <el-table-column prop="recordCompany" label="归属公司" width="160">
                            </el-table-column>
                            <el-table-column prop="createTime" label="创建时间" width="160">
                            </el-table-column>
                            <el-table-column prop="updateTime" label="更新时间" width="160">
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="140">
                                <template slot-scope="scope">
                                    <el-button @click="updateClick(scope.row.id)" type="text"
                                        size="small">修改</el-button>
                                    <el-button @click="delClick(scope.row.id)" type="text" size="small">删除</el-button>
                                </template>
                            </el-table-column>
                        </el-table>
                        <div class="grid-content bg-purple-dark">
                            <div class="block">
                                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                                    :current-page="pageNum" :page-sizes="[5, 10, 20, 50]" :page-size="pageSize"
                                    layout="total, sizes, prev, pager, next, jumper" :total="total">
                                </el-pagination>
                            </div>
                        </div>
                    </span>
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return {
            //搜索
            formInline: {},
            //拒绝 同意
            form: {
                createUser: JSON.parse(localStorage.getItem("user")).id
            },
            pageNum: 1,
            pageSize: 5,
            total: 1,
            tableData: [],
            timeArr: [],
            timeArr1: [],
            title: "新建全宗",
            carNumbers: {},
        }
    },
    created() {
        this.findCarcheer()
        this.getCarNumber()
    },
    methods: {
        //查询指定信息
        getCarNumber() {
            axios.get("/record/findselect").then((res) => {
                console.log(res);
                this.carNumbers = res.data.data;
            });
        },
        //删除
        delClick(id) {
            axios.post("record/delrecord?id=" + id).then((res) => {
                console.log(res)
                if (res.data.code === 200) {
                    this.$message.success(res.data.data)
                    this.findCarcheer()
                }
            })
        },
        // 查询加油记录
        findCarcheer() {
            this.formInline.createStartTime = this.timeArr[0]
            this.formInline.createEndTime = this.timeArr[1]
            this.formInline.updateStartTime = this.timeArr1[0]
            this.formInline.updateEndTime = this.timeArr1[1]
            axios.post("recordcaselocker/findrecordcaselockerPagination?pageSize=" + this.pageSize + "&pageNum=" + this.pageNum, this.formInline).then((res) => {
                console.log(res)
                this.tableData = res.data.data.records
                this.total = res.data.data.total
            })
        },
        //添加加油记录
        openCheer() {
            this.$router.push("addcaselocker")
        },
        //修改
        updateClick(id) {
            this.$router.push({ path: "/addcaselocker", query: { id: id } })
        },
        //搜索
        onSubmit() {
            this.findCarcheer()
            this.$message.success("查询完成")
        },
        //重置
        reset() {
            this.formInline = {}
            this.timeArr = []
            this.findCarcheer()
        },
        //每页条数改变时触发 选择一页显示多少行
        handleSizeChange(val) {
            this.pageSize = val;
            this.findCarcheer();
        },
        //当前页改变时触发 跳转其他页
        handleCurrentChange(val) {
            this.pageNum = val;
            this.findCarcheer();
        },
        handleClose(done) {
            this.$confirm('确认关闭？')
                .then(_ => {
                    done();
                })
                .catch(_ => { });
        }
    }
}
</script>

<style scoped>
/* element-ui样式 */
.el-row {
    margin-bottom: 10px;

    &:last-child {
        margin-bottom: 0;
    }
}

.el-col {
    border-radius: 4px;
}

.bg-purple {
    background: #fff;
    border-radius: 10px;
}

/* 自定义样式 */
/* * {
    margin: 0px;
    padding: 0px;
  } */
.box {
    width: 98%;
    height: 100%;
    margin: auto;
    /* background-color: red; */
}
</style>